<?php

declare(strict_types=1);

namespace App\Controller\Admin;

use App\Controller\BaseController;
use App\Model\Notify;
use App\Model\NotifyClassify;
use Hyperf\HttpServer\Annotation\AutoController;

/**
 * @AutoController()
 */
class NotifyClassifyController extends BaseController
{
    public function lists()
    {
        $data = NotifyClassify::paginate($this->request->limit);

        return $this->success(['items' => $data->items(),'total' => $data->total()]);
    }

    public function store()
    {
        $post = $this->request->inputs(['name','path']);
        NotifyClassify::create($post);

        return $this->message('添加成功');
    }

    public function update()
    {
        $post = $this->request->inputs(['name','path']);
        NotifyClassify::where('id',$this->request->input('id'))->update($post);

        return $this->message('更新成功');
    }

    public function delete()
    {
        $id = $this->request->input('id');


        if (Notify::where('pid',$id)->first()){
            return $this->failed('分类下面有公告,不能删除');
        }

        NotifyClassify::where('id',$id)->delete();

        return $this->message('删除成功');
    }
}
